package department.fc.controller;

import java.sql.SQLException;
import java.util.ArrayList;

import javax.servlet.RequestDispatcher;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import department.fc.common.AttributeAndView;
import department.fc.common.Controller;
import department.fc.domain.Department;
import department.fc.service.DepartmentService;

public class DepartmentListController implements Controller {

	@Override
	public AttributeAndView handleRequest(HttpServletRequest request,
			HttpServletResponse response) throws Exception {

		DepartmentService service = DepartmentService.getInstance();// DAO 객체 조회

		String url = null;
		try {
			ArrayList<Department> list = service.getDepartmentList();
			request.setAttribute("list", list);
			url = "/department_list.jsp";
		} catch (SQLException e) {
			e.printStackTrace();
			request.setAttribute("error_message", e.getMessage());
			url = "/error.jsp";
		}
		RequestDispatcher rdp = request.getRequestDispatcher(url);
		rdp.forward(request, response);

		return null;
	}

}
